package com.cloudxingkong.dianyinke.Student.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.Utils.MySwipeView;
import com.cloudxingkong.dianyinke.Student.bean.MSTest;

import java.util.List;

/**
 * Created by 云星空科技 on 2016/3/24.
 * 我的地址
 */
public class MSListviewAdapter extends BaseAdapter {
    private List<MSTest.ListBean> list;
    private Context context;
    private ListView listView;
    private onTouchDelete onTouchDelete;
//    private onTouchItemPositions touchItemPositions;

    public MSListviewAdapter(List<MSTest.ListBean> list, Context context, ListView listView, MSListviewAdapter.onTouchDelete
            onTouchDelete) {
        this.list = list;
        this.context = context;
        this.listView = listView;
        this.onTouchDelete = onTouchDelete;

    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            convertView=View.inflate(context, R.layout.item_ms_listview,null);
            holder=new ViewHolder();
            holder.tvAddress= (TextView) convertView.findViewById(R.id.item_ms_tv_address);
            holder.tvName= (TextView) convertView.findViewById(R.id.item_ms_tv_name);
            holder.tvPhoneNo= (TextView) convertView.findViewById(R.id.item_ms_tv_phoneno);
            holder.tvZipCode= (TextView) convertView.findViewById(R.id.item_ms_tv_youbian);
            holder.mySwipeView= (MySwipeView) convertView.findViewById(R.id.myswipeview);
            holder.viewDelete= (TextView) convertView.findViewById(R.id.item_ms_view_delete);
            holder.item_ms_ = ((TextView) convertView.findViewById(R.id.item_ms_));
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.mySwipeView.setListView(listView);
        holder.mySwipeView.setTag(holder.mySwipeView.getId(), position);
        holder.tvName.setText(list.get(position).getPeople());
        if (list.get(position).getIsdefault()==1){
           holder.item_ms_.setVisibility(View.VISIBLE);
        }

        holder.tvZipCode.setText(list.get(position).getPoscode());
        holder.tvAddress.setText(list.get(position).getAddr());
        holder.tvPhoneNo.setText(list.get(position).getPhone());
        int id = list.get(position).getId();
        holder.viewDelete.setTag("" + position);

        onTouchDelete.onDelete(holder.viewDelete, position);


        return convertView;
    }

    public interface onTouchDelete{
        void onDelete(TextView deleteView,int position);
    }


    private class ViewHolder{
        TextView tvName,tvPhoneNo,tvAddress,tvZipCode,item_ms_;
        MySwipeView mySwipeView;
        TextView viewDelete;
    }


//    public interface  onTouchItemPositions{
//         void onTouch(int position);
//    }
}
